back to Index

vincent topgear testing

2014-07-20

some code writen by vincent to test topgear


In [3]:
# Cross-notebook include shim
with open("nbinclude.ipynb") as nbinclude_f: # don't rename nbinclude_f
    import IPython.nbformat.current
    get_ipython().run_cell(IPython.nbformat.current.read(nbinclude_f, 'json').worksheets[0].cells[0].input)

In [4]:
nbinclude("robot")

In [5]:
r = Robot()

In [9]:
r.cmd?

In [10]:
r.cmd(self, 1, 1);


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-ef2ef9787292> in <module>()
----> 1 r.cmd(self, 1, 1);

NameError: name 'self' is not defined

In [6]:
r.enable()

In [8]:
r.cmd(1,1)

In [9]:
r.cmd(0,0)

In [10]:
while True: 
    for i in range(0,100):
        r.cmd(i*0.01, i*0.01)
    for i in range(0,100):
        r.cmd(1-i*0.01, 1-i*0.01)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-10-df87e8714518> in <module>()
      3         r.cmd(i*0.01, i*0.01)
      4     for i in range(0,100):
----> 5         r.cmd(1-i*0.01, 1-i*0.01)

<ipython-input-4-a7cb442a1db4> in cmd(self, left, right)
     38     def cmd(self, left, right):
     39 #         self.rlock.acquire()
---> 40         self._cmd(left, right)
     41 #         self.rlock.release()
     42     def _cmd(self, left, right):

<ipython-input-4-a7cb442a1db4> in _cmd(self, left, right)
     44         self.last_right=right
     45         if self.enabled:
---> 46             self.m_left.cmd(-left)
     47             self.m_right.cmd(right)
     48         else:

<ipython-input-4-a7cb442a1db4> in cmd(self, speed)
     11         else:
     12             self.a1.write(0)
---> 13             self.a2.write(-speed)
     14 class Robot:
     15     def __init__(self):

/home/odroid/topgear/python/mbedrpc.pyc in write(self, value)
    190 
    191     def write(self, value):
--> 192         r = self.mbed.rpc(self.name, "write", [str(value)])
    193 
    194     def read(self):

/home/odroid/topgear/python/mbedrpc.pyc in rpc(self, name, method, args)
     86     def rpc(self, name, method, args):
     87         self.ser.write("/" + name + "/" + method + " " + " ".join(args) + "\n")
---> 88         return self.ser.readline().strip()
     89 
     90 class HTTPRPC(mbed):

/usr/lib/python2.7/dist-packages/serial/serialposix.pyc in read(self, size)
    444         read = bytearray()
    445         while len(read) < size:
--> 446             ready,_,_ = select.select([self.fd],[],[], self._timeout)
    447             # If select was used with a timeout, and the timeout occurs, it
    448             # returns with empty lists -> thus abort read operation.

KeyboardInterrupt: 

In [11]:
r.cmd(0,0)

In [12]:
import time

In [13]:
for i in range(0, 10):
    time.sleep(1)
    print(i)


0
1
2
3
4
5
6
7
8
9

In [14]:
while True: 
    for i in range(0,100):
        r.cmd(i*0.01, i*0.01)
        time.sleep(.5)
    for i in range(0,100):
        r.cmd(1-i*0.01, 1-i*0.01)
        time.sleep(.5)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-14-79ff6f63987d> in <module>()
      2     for i in range(0,100):
      3         r.cmd(i*0.01, i*0.01)
----> 4         time.sleep(.5)
      5     for i in range(0,100):
      6         r.cmd(1-i*0.01, 1-i*0.01)

KeyboardInterrupt: 

In [15]:
r.cmd(0,0
      )

In [16]:
while True:
    r.cmd(.5,.5)
    time.sleep(.5)
    r.cmd(-.5,-.5)
    time.sleep(.5)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-16-adaa37c1f61e> in <module>()
      1 while True:
      2     r.cmd(.5,.5)
----> 3     time.sleep(.5)
      4     r.cmd(-.5,-.5)
      5     time.sleep(.5)

KeyboardInterrupt: 

In [17]:
r.cmd(0,0
      )

In [ ]:
r.cmd(0,0)

In [18]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from IPython.display import clear_output, display, HTML

In [19]:
def show_args(**kwargs):
    s = '<h3>Arguments:</h3><table>\n'
    for k,v in kwargs.items():
        s += '<tr><td>{0}</td><td>{1}</td></tr>\n'.format(k,v)
    s += '</table>'
    display(HTML(s))

In [20]:
i = interact(show_args,
         right=(-1.,1.,0.1),
         left=(-1.,1.,0.1));


Arguments:

right-0.5
left-0.3

In [38]:
right


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-38-aa1fd6a0f7b4> in <module>()
----> 1 right

NameError: name 'right' is not defined

In [21]:
def print_two(one, two):
    print(one)
    print(two)

In [22]:
print_two(1,2)


1
2

In [23]:
i = interact(print_two,
             one=(-1.,1.,0.1),
             two=(-1.,1.,0.1));


-0.2
-0.1

In [24]:
i = interact(r.cmd,
             l=(-1.,1.,0.1),
             r=(-1.,1.,0.1));


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-24-8078413974f0> in <module>()
      1 i = interact(r.cmd,
      2              l=(-1.,1.,0.1),
----> 3              r=(-1.,1.,0.1));

/usr/local/lib/python2.7/dist-packages/IPython/html/widgets/interaction.pyc in interact(__interact_f, **kwargs)
    234         #        ...
    235         f = __interact_f
--> 236         w = interactive(f, **kwargs)
    237         f.widget = w
    238         display(w)

/usr/local/lib/python2.7/dist-packages/IPython/html/widgets/interaction.pyc in interactive(__interact_f, **kwargs)
    183     kwargs = kwargs.copy()
    184 
--> 185     new_kwargs = _find_abbreviations(f, kwargs)
    186     # Before we proceed, let's make sure that the user has passed a set of args+kwargs
    187     # that will lead to a valid call of the function. This protects against unspecified

/usr/local/lib/python2.7/dist-packages/IPython/html/widgets/interaction.pyc in _find_abbreviations(f, kwargs)
    158         for name, value, default in _yield_abbreviations_for_parameter(param, kwargs):
    159             if value is empty:
--> 160                 raise ValueError('cannot find widget or abbreviation for argument: {!r}'.format(name))
    161             new_kwargs.append((name, value, default))
    162     return new_kwargs

ValueError: cannot find widget or abbreviation for argument: 'left'

In [25]:
r.cmd(1,1)

In [26]:
r.cmd(0,0)

In [27]:
def drive_robot(left, right):
    r.cmd(left, right)

In [28]:
i = interact(drive_robot,
             left=(-1.,1.,0.1),
             right=(-1.,1.,0.1));

In [29]:
r.cmd(-.35,-.7)
time.sleep(1)
r.cmd(0,0)

In [30]:
r.cmd(.35,.7)
time.sleep(1)
r.cmd(0,0)

In [31]:
def spin(seconds):
    r.cmd(.35,-.7)
    time.sleep(seconds)
    r.cmd(0,0)

In [33]:
spin(.2)

In [34]:
def square():
    for i in range(0,4):
        r.cmd(.35,.7)
        time.sleep(.5)
        r.cmd(0,0)
        spin(.2)

In [36]:
square()

In [97]:
r.cmd(0, 0)

In [ ]: